home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / memcpy.s < prev    next >
Text File  |  1990-11-23  |  728b  |  32 lines

  1. *    char *memcpy(dest, source, len)
  2. *        register char *dest;
  3. *        register char *source;
  4. *        register unsigned int len;
  5.  
  6. .text
  7. .globl _memcpy
  8. _memcpy:
  9.     move.l    4(a7),a1    ; destination
  10.     move.l    8(a7),a0    ; source
  11.     clr.l    d1
  12.     move.l    12(a7),d1    ; number of bytes
  13.     move.l    a1,d0
  14.     btst    #0,d0        ; odd alignment?
  15.     beq    memcpy0
  16.     move.b    (a0)+,(a1)+    ; copy first byte
  17.     subq.l    #1,d1        ; and reduce count
  18. memcpy0:
  19.     move.l    d1,d2        ; save full count value
  20.     lsr.l    #1,d1        ; convert to word count
  21.     bra    memcpy2
  22. memcpy1:
  23.     move.w    (a0)+,(a1)+    ; word copy loop
  24. memcpy2:
  25.     dbra    d1,memcpy1
  26.     btst    #0,d2        ; extra odd byte to copy?
  27.     beq    memcpy3
  28.     move.b    (a0)+,(a1)+    ; copy last byte
  29. memcpy3:
  30.     move.l    4(a7),d0    ; return destination pointer
  31.     rts
  32.